package com.wlc.rabbitmq.topicqueue;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author 王立朝
 * @description 主题生产者
 * @date 2021-12-15 10:05:07
 */
@Component
public class TopicProducer {

    @Resource
    private RabbitTemplate rabbitTemplate;

    public void sendMessageA(){
        for (int i = 0; i < 1; i++) {
            String message = "-----通配符 topic.keyA-----";
            System.out.println("我是生产信息的：" + message);
            rabbitTemplate.convertAndSend("topicExchange", "topic.keyA", message+" "+i);
        }
    }

    public void sendMessageB(){
        for (int i = 0; i < 1; i++) {
            String message = "通配符模式--routingKey=topic.#消息" ;
            System.out.println("我是生产信息的：" + message);
            rabbitTemplate.convertAndSend("topicExchange", "topic.keyD.keyE", message);
            //rabbitTemplate.convertAndSend("topicExchange", "asdcfasdf", message);
        }

    }
}
